<?php /*a:1:{s:55:"D:\xinwujia\xshop\application\admin\view\map\index.html";i:1533630953;}*/ ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="/lib/jquery/1.9.1/jquery.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=KjrPIyTYVkTkFXllMhlwoUzGYG3ZDFU9"></script>
    <title>Title</title>
    <style>
        html,body{
            height: 100%;
            width:100%
        }
        #map{
            height: 100%;
            width:100%
        }
    </style>
</head>
<body>
<div id="map"></div>
<script>
    // 定义一个控件类，即function
    function SearchControl(){
        // 设置默认停靠位置和偏移量
        this.defaultAnchor = BMAP_ANCHOR_TOP_LEFT;
        this.defaultOffset = new BMap.Size(10, 40);
    }
    // 通过JavaScript的prototype属性继承于BMap.Control
    SearchControl.prototype = new BMap.Control();
    SearchControl.prototype.initialize=function(map){
        // 创建一个DOM元素
        var div =$("<div style='width: 50%;margin: 0px 25%'>" +
            "<div class='input-group' style=''>" +
            "<input type='text' class='form-control'>" +
            "<span class='input-group-btn'>" +
            "<button type='button' class='btn btn-primary searchCity'>搜索</button>" +
            "</span>" +
            "</div>" +
            "</div>").get(0);

        // 添加DOM元素到地图中
        map.getContainer().appendChild(div);

        $(".searchCity").on("click",function () {
           $city=$(this).parent().prev().val();
            console.log($city);
            var local = new BMap.LocalSearch(map, {
                renderOptions:{map: map}
            });
            local.search($city);
        });
        //必须返回dom
        return div;
    }


    $(function () {
        var map=new BMap.Map("map");
        var point = new BMap.Point(116.404, 39.915);
        map.centerAndZoom(point, 15);
        map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
        map.addControl(new BMap.NavigationControl());
        map.addControl(new BMap.ScaleControl());
        map.addControl(new BMap.OverviewMapControl());
        map.addControl(new BMap.MapTypeControl());
        map.setCurrentCity("北京"); // 仅当设置城市信息时，MapTypeControl的切换功能才能可用
        map.setMapStyle({style:'night'});

        // 创建控件实例
        var myCtrl = new SearchControl();
        // 添加到地图当中
        map.addControl(myCtrl);

        // 创建控件实例
        var myZoomCtrl = new ZoomControl();
// 添加到地图当中
        map.addControl(myZoomCtrl);
    });

</script>
</body>
</html>